package sandbox.projecteuler;

import java.util.ArrayList;
import java.util.List;

public class ProjectEulerUtils {
	
	public static boolean isPalindrome(String s) {
		int i = 0;
		int j = s.length() - 1;
		while (i < j) {
			if (s.charAt(i++) != s.charAt(j--)) {
				return false;
			}
		}
		return true;
	}
	
	public static long sumOfSquares(int limit) {
		long sum = 0;
		for (long i = 1; i <= limit; i++) {
			sum += i * i;
		}
		return sum;
	}
	
	public static long squareOfSum(int limit) {
		long sum = 0;
		for (long i = 1; i <= limit; i++) {
			sum += i;
		}
		return sum * sum;
	}
	
	public static List<Integer> factors(int num) {
		List<Integer> factors = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			if (num % i == 0) {
				factors.add(Integer.valueOf(i));
			}
		}
		return factors;
	}
	
	public static int numberOfFactors(int num) {
		int count = 0;
		for (int i = 1; i <= num; i++) {
			if (num % i == 0) {
				count++;
			}
		}
		return count;
	}
	
}